package com.huawei.hgip.paintgame.activity;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.huawei.hgip.paintgame.R;
//import com.huawei.hgip.paintgame.app.ZZYYListActivity;
import com.huawei.hgip.paintgame.adapter.HistoryAdapter;
import com.huawei.hgip.paintgame.adapter.HistoryInfo;
import com.huawei.hgip.paintgame.app.ZZYYListActivity;
import com.huawei.hgip.paintgame.m.data.UserProfile;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.Toast;

public class HistoryActivity extends ZZYYListActivity {// 从数据文件中 读取数据并 以列表形式输出
	//ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
	ArrayList<HistoryInfo> historyInfos= new ArrayList<HistoryInfo>();
	private Button backButton = null;

	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.history);
		try {
			historyInfos.clear();
			historyInfos = UserProfile.getHistoryInfos();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			Toast.makeText(HistoryActivity.this, "读取历史记录失败", Toast.LENGTH_SHORT).show();
			e.printStackTrace();
		}
		
		//FrameLayout frameLayout = (FrameLayout) getLayoutInflater().inflate(R.layout.history, null);
        //ListView appListView = (ListView) frameLayout.findViewById(R.id.list);
        HistoryAdapter adapter = new HistoryAdapter(HistoryActivity.this,
        		historyInfos);
        setListAdapter(adapter);
        //return frameLayout;
		/****
		//读取日志并添加到database
		try {
			list.clear();
			list = UserProfile.getLog();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			Toast.makeText(HistoryActivity.this, "读取历史记录失败", Toast.LENGTH_SHORT).show();
			e.printStackTrace();
		}

		SimpleAdapter listAdapter = new SimpleAdapter(this, list,
				R.layout.log, new String[] { "data", "source", "result" },
				new int[] { R.id.data, R.id.source, R.id.result });
		setListAdapter(listAdapter);
		****/
		// 列表提供按钮发送短信或打电话
		// 监听提交和返回按钮
		backButton = (Button) findViewById(R.id.back_button);
		backButton.setOnClickListener(new backListener());
	}

	/***
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		
		String resultUri = historyInfos.get(position).resultUri;
		System.out.println("Current result Uri=" + resultUri);
		// 通过intent传递信息
		Intent intent = new Intent();
		intent.putExtra("resultUri", resultUri);
		Bitmap resultBitmap = historyInfos.get(position).result;
		Drawable result = new BitmapDrawable(resultBitmap); 
		//title不能为空，先设置为 空格
		new AlertDialog.Builder(HistoryActivity.this).setIcon(result).setTitle(" ").show();
	}
	***/

	// 返回按钮监听器
	class backListener implements OnClickListener {

		//@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			finish();
		}
	}
}